﻿using BT.Engine.Components;

namespace BT.Engine
{
    public class Track
    {

        public const int Size = 6;

        public Item[,] Items { get; private set; }

        public Player Player { get; private set; }

        public Input Input { get; set; }

        public Track()
        {
            Items = new Item[3, Size * 2];
            Player = new Player();
            Generate();
        }

        private void Generate()
        {
            Shift();
        }

        private void Shift()
        {
            for (int i = 0; i < Size; i++)
            {
                for (int j = 0; j < Items.GetLength(0); j++)
                {
                    Items[j, i] = Items[j, i + Size];
                    Items[j, i + Size] = null;
                }
            }
        }

        public Item[] Move()
        {
            Player.Index = (Player.Index + 1) % Size;

            if (Player.Index == 0)
                Generate();

            Player.UpdateState(Input);
            Input = Input.None;

            return Player.CheckCollision(Items);
        }

    }
}
